package com.tyqx.hashchainbiz.controller.supplier;

import com.tyqx.hashchainbean.module.ProduceProductIn;
import com.tyqx.hashchainbean.module.ShippingInfo;
import com.tyqx.hashchainbean.vo.ProduceProductInVO;
import com.tyqx.hashchainbean.vo.QueryParamVo;
import com.tyqx.hashchainbean.vo.QueryTimeParamVo;
import com.tyqx.hashchainbiz.service.ProduceProductInService;
import com.tyqx.hashchainbiz.service.QueryDonateService;
import com.tyqx.hashchainbiz.service.TrackDonateService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(description = "产成品入库")
@RestController
@RequestMapping("/produceProductIn")
@CrossOrigin
public class ProduceProductInController {

    @Resource
    private ProduceProductInService produceProductInService;

    @RequestMapping(value="/saveProduceProductIn", method = RequestMethod.POST)
    @ResponseBody
    public String saveProduceProductIn(@RequestBody ProduceProductInVO produceProductInVO) throws Exception {

        String msg="";
        ProduceProductIn produceProductIn=new ProduceProductIn();
        produceProductIn.setEffectTime(produceProductInVO.getEffectTime());
        produceProductIn.setInName(produceProductInVO.getInName());
        produceProductIn.setInNum(produceProductInVO.getInNum());
        produceProductIn.setInPrice(produceProductInVO.getInPrice());
        produceProductIn.setInTime(produceProductInVO.getInTime());
        produceProductIn.setInUnit(produceProductInVO.getInUnit());
        produceProductIn.setProduceTime(produceProductInVO.getProduceTime());
        produceProductIn.setUserName(produceProductInVO.getUserName());
        if(produceProductInService.produceProductIn(produceProductIn)>0){
            msg="添加产成品入库成功";
        }else{
            msg="添加产成品入库失败";
        }
        return msg;
    }

    @RequestMapping(value="/getProduceProductInById", method = RequestMethod.POST,
            produces = "application/json")
    @ResponseBody
    public List<ProduceProductIn> getProduceProductInById(@RequestBody QueryParamVo queryParamVo) throws Exception {

        return produceProductInService.getProduceProductInById(queryParamVo.getDonateId(),queryParamVo.getUserName());
    }

    @RequestMapping(value="/getProduceProductInByTime", method = RequestMethod.POST,
            produces = "application/json")
    @ResponseBody
    public List<ProduceProductIn> getProduceProductInByTime(@RequestBody QueryTimeParamVo queryTimeParamVo) throws Exception {

        return produceProductInService.getProduceProductInByTime(queryTimeParamVo.getStartTime(),
                queryTimeParamVo.getEndTime(),queryTimeParamVo.getUserName());
    }
}
